package com.module.TraceSource.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.module.TraceSource.vo.TsDefEventItem;

import base.dao.GenericHibernateDao;
import base.util.Page;

public class TsDefEventItemDao extends GenericHibernateDao<TsDefEventItem, Long>{
	private static TsDefEventItemDao dao;

	public TsDefEventItemDao() {
		super();
	}
	
	public synchronized static TsDefEventItemDao getInstance(){
		if(dao == null){
			dao = new TsDefEventItemDao();
		}
		return dao;
	}
	
	/**
	 * 分页列出操作事项字段列表
	 * @param session
	 * @param obj
	 * @param page
	 * @return
	 */
	public Page getList(Session session, TsDefEventItem obj, Page page) {
		String hql1 = "from TsDefEventItem as obj where obj.status !='D' ";
		String hql2 = "select count(*) from TsDefEventItem as obj where obj.status !='D' ";
		if(obj.getEventid()!=null && obj.getEventid()!=0){
			hql1=hql1 +  " and obj.eventid = "+obj.getEventid();
            hql2=hql2 +  " and obj.eventid = "+obj.getEventid();
		}
		Query query = session.createQuery(hql1);
        query.setFirstResult(page.getStart()).setMaxResults(page.getLimit());
        page.setTotal((long) ((Long) session.createQuery(hql2)
                .uniqueResult()).intValue());
        page.setRows(query.list());
		return page;
	}
}
